package com.ruoyi.eqmonitor.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.eqmonitor.dispose.service.IotService;
import com.ruoyi.eqmonitor.service.ISnCodeRelationService;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * @author jiangyu on 2023/3/23
 */
@RequestMapping("device")
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestController {
    @Resource
    private IotService iotService;
    private static final String ROOT_HX = "root.hx.yjbz.";
    @RequestMapping("shutdown")
    public String shutdown() throws IOException {
       /* String s1 = SSH.remoteExec("ps -ef|grep tomcat", "192.168.0.225", "root", "!%1q2w3e4r88");
        System.out.println(s1);*/
        return "";
    }

    public static void main(String[] args) {
        double d = Double.parseDouble("0.0");
        if(d!=0){
            System.err.println("aaaaaaaaaaaaaaaaaaa");
        }else {
            System.err.println("bbbbbbbbbbb");
        }
    }
    @RequestMapping("insert")
    public void insert(){
        List<String> measurements = new ArrayList<>();
        measurements.add("s1");
        measurements.add("s2");
        measurements.add("s3");
        measurements.add("s4");
        measurements.add("s5");
        List<Object> values = new ArrayList<>();
        values.add(80.2f);
        values.add(34f);
        values.add(45.3f);
        values.add(45);
        values.add(true);
        List<TSDataType> types = new ArrayList<>();
        types.add(TSDataType.FLOAT);
        types.add(TSDataType.FLOAT);
        types.add(TSDataType.FLOAT);
        types.add(TSDataType.INT32);
        types.add(TSDataType.BOOLEAN);
        iotService.insertAlignedRecord("NOTM002",System.currentTimeMillis(),measurements , types, values);
    }
    @NonNull
    private ISnCodeRelationService snCodeRelationService;
    @RequestMapping("snCodeRelation")
    public void snCodeRelation(){
        System.out.println(JSONObject.toJSONString(snCodeRelationService.list()));
    }

}
